<?php

namespace app\api\controller;

class Banner
{
    public $pagesize = 5;


    public function lists()
    {
        $position = trim(input("request.position"));//位置
//        $auth = trim(input("request.auth"));//用户auth
//        $userInfo = checkLoginExp($auth);
//        if (empty($userInfo)) {
//            $return = ['err' => 1, 'msg' => '获取失败,未登录', 'devMsg' => '获取失败，参数错误[auth]'];
//            return json($return);
//        }


        $w = array();
        $w['is_delete'] = 0;//未删除
        $w['stats'] = 0;//已上架

        if (!empty($position)) {
            $tempPosition = explode(",", $position);
            $tempPosition = array_filter($tempPosition);
            if (empty($tempPosition)) {
                $return['err'] = 1;
                $return['msg'] = '参数错误，';
                $return['devMsg'] = '获取失败，参数错误[position]';
                return json($return);
            }
            $w['position'] = array('in', $tempPosition);//广告图位置
        }

        $model = new \app\admin\model\Ad();
        $lists = $model->getDataForWheres($w, "id,name,img,optype,opval,funval,position", "sorts asc", 200);
        $return['err'] = 0;
        $return['msg'] = '获取成功';
        $return['data'] = $lists;
        return json($return);
    }


    public function wechatLists()
    {
        $position = trim(input("request.position"));//位置


//        $access_token = trim($_REQUEST['access_token']);
//        $userModel = new \app\admin\model\User();
//       $_hosp = trim($_REQUEST['_hosp']);
//        if (empty($_hosp)) {
//            $return['err'] = 1;
//            $return['msg'] = '参数错误[_hosp]';
//            return json($return);
//        }
//        $userInfo = getUserinfoForAccessToken($access_token,1,$_hosp);
//        if (empty($userInfo)) {
//            $userInfo = getUserinfoForAccessToken($access_token,2,$_hosp);
//            if (empty($userInfo)) {
//                $return['err'] = 10009;
//                $return['msg'] = '未找到相关用户';
//                echo json_encode($return, true);
//                exit;
//            }
//        }

        $w = array();
        $w['is_delete'] = 0;//未删除
        $w['stats'] = 0;//已上架

        if (!empty($position)) {
            $tempPosition = explode(",", $position);
            $tempPosition = array_filter($tempPosition);
            if (empty($tempPosition)) {
                $return['err'] = 1;
                $return['msg'] = '参数错误，';
                $return['devMsg'] = '获取失败，参数错误[position]';
                return json($return);
            }
            $w['position'] = array('in', $tempPosition);//广告图位置
        }

        $model = new \app\admin\model\Ad();
        $lists = $model->getDataForWheres($w, "id,name,img,optype,opval,funval,position", "sorts asc", 200);
        $return['err'] = 0;
        $return['msg'] = '获取成功';
        $return['data'] = $lists;
        return json($return);
    }

}
